<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>LoadingManager - Three.js Docs</title>
	<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
	<script src="../scripts/highlight.min.js"></script>
	<link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
	<link type="text/css" rel="stylesheet" href="../styles/page.css">
</head>
<body>
	<h1 translate="no">LoadingManager</h1>
		<section>
			<header>
				<div class="class-description"><p>Handles and keeps track of loaded and pending data. A default global
instance of this class is created and used by loaders if not supplied
manually.</p>
<p>In general that should be sufficient, however there are times when it can
be useful to have separate loaders - for example if you want to show
separate loading bars for objects and textures.</p></div>
				<h2>Code Example</h2>
				<div translate="no"><pre><code class="language-js">const manager = new THREE.LoadingManager();
manager.onLoad = () => console.log( 'Loading complete!' );
const loader1 = new OBJLoader( manager );
const loader2 = new ColladaLoader( manager );
</code></pre></div>
			</header>
			<article>
				<div class="container-overview">
					<h2>Constructor</h2>
					<h3 class="name name-method" id="LoadingManager" translate="no">new <a href="#LoadingManager">LoadingManager</a><span class="signature">( onLoad : <span class="param-type">function</span>, onProgress : <span class="param-type">function</span>, onError : <span class="param-type">function</span> )</span> </h3>
					<div class="method">
						<div class="description">
							<p>Constructs a new loading manager.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>onLoad</strong>
									</td>
									<td class="description last">
										<p>Executes when all items have been loaded.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>onProgress</strong>
									</td>
									<td class="description last">
										<p>Executes when single items have been loaded.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>onError</strong>
									</td>
									<td class="description last">
										<p>Executes when an error occurs.</p>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
				<h2 class="subsection-title">Properties</h2>
				<div class="member">
					<h3 class="name" id="abortController" translate="no">.<a href="#abortController">abortController</a><span class="type-signature"> : AbortController</span> </h3>
					<div class="description">
						<p>Used for aborting ongoing requests in loaders using this manager.</p>
					</div>
				</div>
				<div class="member">
					<h3 class="name" id="onError" translate="no">.<a href="#onError">onError</a><span class="type-signature"> : function | undefined</span> </h3>
					<div class="description">
						<p>Executes when an error occurs.</p>
						<p>Default is <code>undefined</code>.</p>
					</div>
				</div>
				<div class="member">
					<h3 class="name" id="onLoad" translate="no">.<a href="#onLoad">onLoad</a><span class="type-signature"> : function | undefined</span> </h3>
					<div class="description">
						<p>Executes when all items have been loaded.</p>
						<p>Default is <code>undefined</code>.</p>
					</div>
				</div>
				<div class="member">
					<h3 class="name" id="onProgress" translate="no">.<a href="#onProgress">onProgress</a><span class="type-signature"> : function | undefined</span> </h3>
					<div class="description">
						<p>Executes when single items have been loaded.</p>
						<p>Default is <code>undefined</code>.</p>
					</div>
				</div>
				<div class="member">
					<h3 class="name" id="onStart" translate="no">.<a href="#onStart">onStart</a><span class="type-signature"> : function | undefined</span> </h3>
					<div class="description">
						<p>Executes when an item starts loading.</p>
						<p>Default is <code>undefined</code>.</p>
					</div>
				</div>
				<h2 class="subsection-title">Methods</h2>
					<h3 class="name name-method" id="abort" translate="no">.<a href="#abort">abort</a><span class="signature">()</span><span class="type-signature"> : <a href="LoadingManager.html">LoadingManager</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Can be used to abort ongoing loading requests in loaders using this manager.
The abort only works if the loaders implement <a href="Loader.html#abort">Loader#abort</a> and <code>AbortSignal.any()</code>
is supported in the browser.</p>
						</div>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this loading manager.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="addHandler" translate="no">.<a href="#addHandler">addHandler</a><span class="signature">( regex : <span class="param-type">string</span>, loader : <span class="param-type"><a href="Loader.html">Loader</a></span> )</span><span class="type-signature"> : <a href="LoadingManager.html">LoadingManager</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Registers a loader with the given regular expression. Can be used to
define what loader should be used in order to load specific files. A
typical use case is to overwrite the default loader for textures.</p>
<pre><code class="language-js">// add handler for TGA textures
manager.addHandler( /\.tga$/i, new TGALoader() );
</code></pre>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>regex</strong>
									</td>
									<td class="description last">
										<p>A regular expression.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>loader</strong>
									</td>
									<td class="description last">
										<p>A loader that should handle matched cases.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this loading manager.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="getHandler" translate="no">.<a href="#getHandler">getHandler</a><span class="signature">( file : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="Loader.html">Loader</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Can be used to retrieve the registered loader for the given file path.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>file</strong>
									</td>
									<td class="description last">
										<p>The file path.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The registered loader. Returns <code>null</code> if no loader was found.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="itemEnd" translate="no">.<a href="#itemEnd">itemEnd</a><span class="signature">( url : <span class="param-type">string</span> )</span> </h3>
					<div class="method">
						<div class="description">
							<p>This should be called by any loader using the manager when the loader
ended loading an item.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>url</strong>
									</td>
									<td class="description last">
										<p>The URL of the loaded item.</p>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<h3 class="name name-method" id="itemError" translate="no">.<a href="#itemError">itemError</a><span class="signature">( url : <span class="param-type">string</span> )</span> </h3>
					<div class="method">
						<div class="description">
							<p>This should be called by any loader using the manager when the loader
encounters an error when loading an item.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>url</strong>
									</td>
									<td class="description last">
										<p>The URL of the item that produces an error.</p>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<h3 class="name name-method" id="itemStart" translate="no">.<a href="#itemStart">itemStart</a><span class="signature">( url : <span class="param-type">string</span> )</span> </h3>
					<div class="method">
						<div class="description">
							<p>This should be called by any loader using the manager when the loader
starts loading an item.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>url</strong>
									</td>
									<td class="description last">
										<p>The URL to load.</p>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<h3 class="name name-method" id="removeHandler" translate="no">.<a href="#removeHandler">removeHandler</a><span class="signature">( regex : <span class="param-type">string</span> )</span><span class="type-signature"> : <a href="LoadingManager.html">LoadingManager</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Removes the loader for the given regular expression.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>regex</strong>
									</td>
									<td class="description last">
										<p>A regular expression.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this loading manager.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="resolveURL" translate="no">.<a href="#resolveURL">resolveURL</a><span class="signature">( url : <span class="param-type">string</span> )</span><span class="type-signature"> : string</span> </h3>
					<div class="method">
						<div class="description">
							<p>Given a URL, uses the URL modifier callback (if any) and returns a
resolved URL. If no URL modifier is set, returns the original URL.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>url</strong>
									</td>
									<td class="description last">
										<p>The URL to load.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The resolved URL.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="setURLModifier" translate="no">.<a href="#setURLModifier">setURLModifier</a><span class="signature">( transform : <span class="param-type">function</span> )</span><span class="type-signature"> : <a href="LoadingManager.html">LoadingManager</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>If provided, the callback will be passed each resource URL before a
request is sent. The callback may return the original URL, or a new URL to
override loading behavior. This behavior can be used to load assets from
.ZIP files, drag-and-drop APIs, and Data URIs.</p>
<pre><code class="language-js">const blobs = {'fish.gltf': blob1, 'diffuse.png': blob2, 'normal.png': blob3};
const manager = new THREE.LoadingManager();
// Initialize loading manager with URL callback.
const objectURLs = [];
manager.setURLModifier( ( url ) => {
	url = URL.createObjectURL( blobs[ url ] );
	objectURLs.push( url );
	return url;
} );
// Load as usual, then revoke the blob URLs.
const loader = new GLTFLoader( manager );
loader.load( 'fish.gltf', (gltf) => {
	scene.add( gltf.scene );
	objectURLs.forEach( ( url ) => URL.revokeObjectURL( url ) );
} );
</code></pre>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>transform</strong>
									</td>
									<td class="description last">
										<p>URL modifier callback. Called with an URL and must return a resolved URL.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this loading manager.</dt>
						</dl>
					</div>
				<h2 class="subsection-title">Source</h2>
				<p>
					<a href="https://github.com/mrdoob/three.js/blob/master/src/loaders/LoadingManager.js" translate="no" target="_blank" rel="noopener">src/loaders/LoadingManager.js</a>
				</p>
			</article>
		</section>
<script src="../scripts/linenumber.js"></script>
<script src="../scripts/page.js"></script>
</body>
</html>